<?php

namespace App\Modules\Admin\Console\OneDragon;

use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class OneDragonMakeController extends GeneratorCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'make:one-dragon-controller {name}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new one-dragon-controller.';

    /**
     * The type of class being generated.
     *
     * @var string
     */
    protected $type = 'Controllers';

    /**
     * Get the stub file for the generator.
     *
     * @return string
     */
    protected function getStub()
    {
        return dirname(__DIR__) . '/stubs/controller.plain.stub';
    }

    /**
     * Get the default namespace for the class.
     *
     * @param  string  $rootNamespace
     * @return string
     */
    protected function getDefaultNamespace ( $rootnamespace )
    {
        return 'App\Modules\Admin\Http\Controllers';
    }

    protected function replaceNamespace(&$stub, $name)
    {
        $parent = parent::replaceNamespace($stub, $name); // TODO: Change the autogenerated stub

        $param_name = str_replace('Controller', '', $this->argument('name'));

        $request_name = $param_name . 'Request';
        $service_name = $param_name . 'Service';

        $stub = str_replace(
            ['{{ request_namespace }}', '{{ request }}'],
            [$this->getRequestspace($request_name), $request_name],
            $stub
        );

        $stub = str_replace(
            ['{{ service_namespace }}', '{{ service }}'],
            [$this->getServicespace($service_name), $service_name],
            $stub
        );

        return $parent;
    }

    protected function getRequestspace($name)
    {
        return 'App\Modules\Admin\Http\Requests\\' . $name;
    }

    protected function getServicespace($name)
    {
        return 'App\Modules\Admin\Services\\' . $name;
    }
}
